<template>
	<view class="cont">
		<view class="title">请输入正确数字密码</view>
		<view class="title">解锁智能门锁</view>
		<input
			class="input"
			placeholder="请输入正确密码"
			name="deviceName"
			v-model="password"
			:password="true"
		/>
		<view class="tips">改密码用于远程开锁，通过手机远程，即可打开家门 </view>
		
		<view class="u-f-ajc conf" @click="confirmUnlock">确定</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				// 设备对象
				device: {
					deviceName: '',
					token:''
				},
				password:''
				
			}
		},
		onLoad(opt) {
			console.log(opt);
			this.device = JSON.parse(opt.device)
			console.log('name==:',this.device.deviceName);
		},
		methods:{
			//远程开锁
			confirmUnlock(){
				uni.showLoading({
					title:'正在开锁'
				})
				let token = this.device.token;
				let data = {
					sn: this.device.deviceNo,
					props:{
						doorLock: {
						    remoteUnlock:{
						        password:this.password
						    }
						}
					}
				};
				getApp().globalData.api.remoteUnlock(data, token, (result) => {
					console.log('设备开锁===>：', result);
					uni.hideLoading();
					if (result.Ret === 100) {
						uni.showToast({
						    title: '开锁成功',
							success: () => {
								setTimeout(()=>{
									uni.navigateBack({ })
								},1000)
							}
						});
					}else {
					    uni.showToast({
					        title: result.RetMsg
					    });
					}
				});
				
			},
			
			
		}
	}
</script>

<style lang="scss">
	.cont{
		padding: 30rpx;
		.title{
			font-size: 40rpx;
			font-family: Source Han Sans CN;
			font-weight: 600;
			line-height: 60rpx;
			color: #000000;
		}
		.input{
			margin-top: 52rpx;
			background: #ffffff;
			padding: 20rpx;
		}
		.tips{
			margin-top: 30rpx;
			font-size: 26rpx;
			font-family: SourceHanSansCN-Regular;
			line-height: 41rpx;
			color: #8A8A8A;
		}
		.conf{
			margin-top: 52rpx;
			width: 100%;
			height: 84rpx;
			background: #ffffff;
			border: 1rpx solid #B9B9B9;
			border-radius: 15rpx;
			ont-size: 30rpx;
			color: #FF0025;
			font-weight: 700;
		}
	}
	
</style>